/**
 * Test Data Generator for TaskMaster E2E Tests
 * AceFlow v3.0 - E2E Testing Phase
 */

/**
 * Generate unique test user data
 * @param {string} prefix - Username prefix
 * @returns {Object} User data object
 */
export function generateTestUser(prefix = 'testuser') {
  const timestamp = Date.now();
  const random = Math.floor(Math.random() * 1000);

  return {
    username: `${prefix}_${timestamp}_${random}`,
    password: 'TestPass123!@#Secure',
    email: `${prefix}_${timestamp}_${random}@example.com`
  };
}

/**
 * Generate test task data
 * @param {string} title - Task title
 * @returns {Object} Task data object
 */
export function generateTestTask(title = 'Test Task') {
  const timestamp = Date.now();

  return {
    title: `${title} ${timestamp}`,
    description: `This is a test task created at ${new Date(timestamp).toISOString()}`,
    dueDate: '2025-09-15T10:00:00',
    priority: 2
  };
}

/**
 * Generate multiple test users
 * @param {number} count - Number of users to generate
 * @returns {Array} Array of user data objects
 */
export function generateTestUsers(count = 3) {
  const users = [];
  for (let i = 0; i < count; i++) {
    users.push(generateTestUser(`user${i + 1}`));
  }
  return users;
}

/**
 * Generate multiple test tasks
 * @param {number} count - Number of tasks to generate
 * @returns {Array} Array of task data objects
 */
export function generateTestTasks(count = 5) {
  const tasks = [];
  for (let i = 0; i < count; i++) {
    tasks.push(generateTestTask(`Task ${i + 1}`));
  }
  return tasks;
}

/**
 * Test data constants
 */
export const TEST_CONSTANTS = {
  BASE_URL: 'http://localhost:5173',
  API_BASE_URL: 'http://localhost:8000',

  // Wait times
  WAIT_SHORT: 1000,
  WAIT_MEDIUM: 3000,
  WAIT_LONG: 5000,

  // Selectors
  SELECTORS: {
    // Navigation
    NAV_LOGIN: '[data-testid="nav-login"]',
    NAV_REGISTER: '[data-testid="nav-register"]',
    NAV_LOGOUT: '[data-testid="nav-logout"]',

    // Forms
    FORM_LOGIN: '[data-testid="login-form"]',
    FORM_REGISTER: '[data-testid="register-form"]',
    FORM_TASK: '[data-testid="task-form"]',

    // Inputs
    INPUT_USERNAME: '[data-testid="username-input"]',
    INPUT_PASSWORD: '[data-testid="password-input"]',
    INPUT_EMAIL: '[data-testid="email-input"]',
    INPUT_TASK_TITLE: '[data-testid="task-title-input"]',
    INPUT_TASK_DESCRIPTION: '[data-testid="task-description-input"]',
    INPUT_TASK_DUE_DATE: '[data-testid="task-due-date-input"]',
    INPUT_TASK_PRIORITY: '[data-testid="task-priority-select"]',

    // Buttons
    BTN_LOGIN: '[data-testid="login-button"]',
    BTN_REGISTER: '[data-testid="register-button"]',
    BTN_ADD_TASK: '[data-testid="add-task-button"]',
    BTN_SAVE_TASK: '[data-testid="save-task-button"]',
    BTN_EDIT_TASK: '[data-testid="edit-task-button"]',
    BTN_DELETE_TASK: '[data-testid="delete-task-button"]',
    BTN_CONFIRM_DELETE: '[data-testid="confirm-delete-button"]',

    // Lists and items
    TASK_LIST: '[data-testid="task-list"]',
    TASK_ITEM: '[data-testid="task-item"]',
    TASK_TITLE: '[data-testid="task-title"]',
    TASK_DESCRIPTION: '[data-testid="task-description"]',

    // Messages
    MSG_SUCCESS: '[data-testid="success-message"]',
    MSG_ERROR: '[data-testid="error-message"]',
    MSG_LOADING: '[data-testid="loading-message"]'
  }
};

/**
 * Predefined test scenarios data
 */
export const TEST_SCENARIOS = {
  USER_REGISTRATION: {
    validUser: generateTestUser('reguser'),
    duplicateUser: {
      username: 'existing_user',
      password: 'testpass123',
      email: 'existing@example.com'
    },
    invalidUser: {
      username: '',
      password: '',
      email: 'invalid-email'
    }
  },

  USER_LOGIN: {
    validCredentials: {
      username: 'testuser_login',
      password: 'testpass123'
    },
    invalidCredentials: {
      username: 'testuser_login',
      password: 'wrongpassword'
    },
    nonExistentUser: {
      username: 'nonexistent_user',
      password: 'testpass123'
    }
  },

  TASK_MANAGEMENT: {
    newTask: generateTestTask('E2E Test Task'),
    updateTask: {
      title: 'Updated Task Title',
      description: 'Updated task description',
      priority: 1
    }
  }
};

/**
 * Browser configurations for different test scenarios
 */
export const BROWSER_CONFIGS = {
  DESKTOP: {
    viewport: { width: 1280, height: 720 },
    deviceScaleFactor: 1,
  },

  MOBILE: {
    viewport: { width: 375, height: 667 },
    deviceScaleFactor: 2,
    isMobile: true,
    hasTouch: true,
  },

  TABLET: {
    viewport: { width: 768, height: 1024 },
    deviceScaleFactor: 1,
    isMobile: true,
    hasTouch: true,
  }
};
